package com.zsh.rabbitmq.springbootrabbitmq.controller;

import com.zsh.rabbitmq.springbootrabbitmq.config.ConfirmConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zsh
 * @Description 发布确认高级模式
 * @create 2022-05-07 16:33
 */
@Slf4j
@RestController
@RequestMapping("/confirm")
public class ProducerController {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    //发消息
    @GetMapping("/sendMsg/{message}")
    public void sendMsg(@PathVariable String message){

        CorrelationData correlationData = new CorrelationData("1");

        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME,
                ConfirmConfig.ROUTING_KEY,message+"k1",correlationData);

        log.info("发送消息内容为：{}",message+"k1");

        CorrelationData correlationData2 = new CorrelationData("2");

        rabbitTemplate.convertAndSend(ConfirmConfig.CONFIRM_EXCHANGE_NAME,
                ConfirmConfig.ROUTING_KEY+"2",message+"k2",correlationData2);

        log.info("发送消息内容为：{}",message+"k2");



    }

}
